/*
 红外避障：
 
  0 - 检测到物体，输出低电平
  
  ESP32-C3开发板载的2路贴片LED指示灯:D4,D5(GPIO12,13)。
  
  红外避障模块out使用GPIO12,13，没有检测到物体时，信号为高电平，所以，2路贴片LED指示灯会常亮
*/
#ifndef IR_AVOID_H
#define IR_AVOID_H

#include "component_drv8833.h"
#include <Arduino.h>

int left_ir_avoid_pin = 12;
int left_ir_avoid_val;
int right_ir_avoid_pin = 13;
int right_ir_avoid_val;

void setup_ir_avoid()
{
  pinMode(left_ir_avoid_pin, OUTPUT);
  pinMode(right_ir_avoid_pin, OUTPUT);
  // 没有检测到物体时，信号为高电平
  digitalWrite(left_ir_avoid_pin, HIGH);
  digitalWrite(right_ir_avoid_pin, HIGH);
}

void loop_ir_avoid()
{

  left_ir_avoid_val = digitalRead(left_ir_avoid_pin);
  right_ir_avoid_val = digitalRead(right_ir_avoid_pin);
  if (left_ir_avoid_val == 0)
  {
    int cur_cmd = DEV_STOP;
    car_action(cur_cmd);
  }
  if (right_ir_avoid_val == 0)
  {
    int cur_cmd = DEV_STOP;
    car_action(cur_cmd);
  }
}

#endif /* IR_AVOID_H */